home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / ixemlsrc.lha / ixemul / glue / gen_glue.c next >
C/C++ Source or Header  |  1995-12-31  |  2KB  |  112 lines

  1. #include <sys/types.h>
  2. #include <sys/syscall.h>
  3.  
  4. #include <stdio.h>
  5.  
  6. struct syscall {
  7.   char *name;
  8.   int   vec;
  9. } syscalls[] = {
  10. #define SYSTEM_CALL(func,vec) { #func, vec},
  11. #include <sys/syscall.def>
  12. #undef SYSTEM_CALL
  13. };
  14.  
  15. int nsyscall = sizeof(syscalls) / sizeof (syscalls[0]);
  16.  
  17. #define BASEREL             \
  18. ".globl _%s;                \
  19. _%s: movel a4@(_ixemulbase:W), a0;    \
  20. lea a0@(%d),a0;                \
  21. jmp a0@\n"
  22.  
  23. #define BASEREL_IX_GETA4        \
  24. ".globl _%s;                \
  25. _%s: movel _ixemulbase, a0;        \
  26. lea a0@(%d),a0;                \
  27. jmp a0@\n"
  28.  
  29. #define NOBASEREL            \
  30. ".globl _%s;                \
  31. _%s: movel _ixemulbase, a0;        \
  32. lea a0@(%d),a0;                \
  33. jmp a0@\n"
  34.  
  35. #define PROFILING            \
  36. ".globl _%s;                \
  37. _%s:                    \
  38. .data;                    \
  39. PROF%s:;                \
  40. .long 0;                \
  41. .text;                    \
  42. link a5,#0;                \
  43. lea PROF%s,a0;                \
  44. jsr mcount;                \
  45. unlk a5;                \
  46. movel _ixemulbase, a0;            \
  47. lea a0@(%d),a0;                \
  48. jmp a0@\n"
  49.  
  50. void usage(void)
  51. {
  52.   fprintf(stderr, "Usage: gen_glue baserel | no-baserel | profiling\n");
  53.   exit(1);
  54. }
  55.  
  56. int main(int argc, char **argv)
  57. {
  58.   FILE *fp;
  59.   struct syscall *sc;
  60.   int i, v, baserel = 0, profiling = 0;
  61.  
  62.   if (argc != 2)
  63.     usage();
  64.   if (!strcmp(argv[1], "baserel"))
  65.     {
  66.       baserel = 1; profiling = 0;
  67.     }
  68.   else if (!strcmp(argv[1], "no-baserel"))
  69.     {
  70.       baserel = 0; profiling = 0;
  71.     }
  72.   else if (!strcmp(argv[1], "profiling"))
  73.     {
  74.       baserel = 0; profiling = 1;
  75.     }
  76.   else usage();
  77.   
  78.   for (i = 0, sc = syscalls; i < nsyscall; i++, sc++)
  79.     {
  80.       char name[strlen (sc->name) + 3];
  81.  
  82.       if (!memcmp(sc->name, "__obsolete", 10))
  83.         continue;
  84.       if (!memcmp(sc->name, "__must_recompile", 16))
  85.         continue;
  86.       if (!memcmp(sc->name, "___stk", 6))
  87.         continue;
  88.       v = -(sc->vec + 4)*6;
  89.       sprintf (name, "%s.s", sc->name);
  90.  
  91.       fp = fopen (name, "w");
  92.       
  93.       if (!fp)
  94.         {
  95.           perror (sc->name);
  96.           exit (20);
  97.         }
  98.  
  99.       if (baserel)
  100.         if (sc->vec == SYS_ix_geta4)
  101.           fprintf (fp, BASEREL_IX_GETA4, sc->name, sc->name, v);
  102.     else
  103.           fprintf (fp, BASEREL, sc->name, sc->name, v);
  104.       else if (profiling)
  105.         fprintf (fp, PROFILING, sc->name, sc->name, sc->name, sc->name, v);
  106.       else
  107.         fprintf (fp, NOBASEREL, sc->name, sc->name, v);
  108.       fclose (fp);
  109.     }
  110.   return (0);
  111. }
  112.